package com.zzvcom.office.vo;

import lombok.Data;

/**
 * 定义返回类型格式。
 * @param <T>
 */
@Data
public class ResultVo<T> implements java.io.Serializable
{
    public static final String CODE_SUCCESS = "200";
    public static final String CODE_WARNING = "204";
    public static final String CODE_FAIL = "500";
    private static final long serialVersionUID = 1L;
    /**
     * 相应编码
     */
    private String code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 响应消息明细
     */
    private String detailMessage;
    private T data;

    public   static <T> ResultVo<T> valueOf(String code, String message, T data)
    {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public   static <T> ResultVo<T> valueOf(String code, String message)
    {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    /**
     * 成功消息
     * @param message 消息汇总消息
     * @param detailMessage 消息细节
     * @param data 数据
     * @return
     * @param <T>
     */
    public   static <T> ResultVo<T> success(String message,String detailMessage,T data)
    {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(CODE_SUCCESS);
        result.setMessage(message);
        result.setData(data);
        result.setDetailMessage(detailMessage);
        return result;
    }

    /**
     * 错误消息
     * @param message
     * @param detailMessage
     * @return
     * @param <T>
     */
    public   static <T> ResultVo<T> error(String message,String detailMessage)
    {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(CODE_FAIL);
        result.setMessage(message);
        result.setDetailMessage(detailMessage);
        return result;
    }

    /**
     * 警告消息
     * @param message
     * @param detailMessage
     * @return
     * @param <T>
     */
    public   static <T> ResultVo<T> warning(String message,String detailMessage)
    {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(CODE_WARNING);
        result.setMessage(message);
        result.setDetailMessage(detailMessage);
        return result;
    }
}
